﻿using JshRCSWebApi.Infrastructure;
using JshRCSWebApi.Infrastructure.Domain.DTO.SysVehicle;
using JshRCSWebApi.Infrastructure.Domain.DTO.SysVehicle.VehicleConfig;
using JshRCSWebApi.Infrastructure.Domain.VO;
using JshRCSWebApi.Infrastructure.Domain.VO.SysVehicle.VehicleConfig;
using JshRCSWebApi.Service.SysVehicle;
using JshRCSWebApi.SqlSugarDB.Model.jshrcs_initial;
using JshRCSWebApi.Util;
using JshRCSWebApi.Util.Json;
using JshRCSWebApi.Util.VehicelTool;
using JshRCSWebApi.Util.VehicleTool;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using SqlSugar.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace JshRCSWebApi.ServiceImpl.SysVehicle
{
    public class VehicleConfigServiceImpl : VehicleConfigService
    {
        private readonly Repository<dynamic> _repository;
        private int vehiclePort = 19207;
        public VehicleConfigServiceImpl(Repository<dynamic> repository)
        {
            _repository = repository;
        }
        /// <summary>
        /// 上传地图到机器人 4010 
        /// </summary>
        /// <param name="requestDTO"></param>
        /// <returns></returns>
        public async Task<ApiResult> robot_config_uploadmap_req(RequestDTO<robot_config_downloadmap_VO> requestDTO)
        {
            RequestDTO request = new RequestDTO();
            request.vehiclePort = vehiclePort;
            request.vehicleIP = requestDTO.vehicleIP;
            request.number = 4010;
            request.askJson = JsonConvert.SerializeObject(requestDTO.askJson);
            try
            {
                SeerTcpClient client = new SeerTcpClient(requestDTO.vehicleIP, request.vehiclePort);
                if (client.Connected)
                {
                    var str = client.SendseerMessage(request);
                    return await Task.Run(async () => ApiResult.Success("ok", JsonConvert.DeserializeObject<ResponseVO>(str)));
                }
                else
                    return await Task.Run(async () => ApiResult.Error("机器人网络连接断开，请检查网络"));
            }
            catch (SocketException)
            {
                return await Task.Run(async () => ApiResult.Error("SocketException"));
            }
            catch (IOException)
            {
                return await Task.Run(async () => ApiResult.Error("IOException"));
            }
        }
        /// <summary>
        /// 抢占控制权 4005
        /// </summary>
        /// <param name="requestDTO"></param>
        /// <returns></returns>
        public async Task<ApiResult> robot_config_lock_req(RequestDTO<robot_config_lock_DTO> requestDTO)
        {
            RequestDTO request = new RequestDTO();
            request.vehiclePort = vehiclePort;
            request.vehicleIP = requestDTO.vehicleIP;
            request.number = 4005;
            request.askJson = JsonConvert.SerializeObject(requestDTO.askJson);
            try
            {
                SeerTcpClient client = new SeerTcpClient(requestDTO.vehicleIP, request.vehiclePort);
                if (client.Connected)
                { 
                    var str = client.SendseerMessage(request);
                    return await Task.Run(async () => ApiResult.Success("ok", JsonConvert.DeserializeObject<ResponseVO>(str)));
                }
                else 
                    return await Task.Run(async () => ApiResult.Error("机器人网络连接断开，请检查网络")); 
            }
            catch (SocketException)
            { 
                return await Task.Run(async () => ApiResult.Error("SocketException"));
            }
            catch (IOException)
            {
                return await Task.Run(async () => ApiResult.Error("IOException")); 
            }
        }
        /// <summary>
        /// 释放控制权 4006 
        /// </summary>
        /// <param name="requestDTO"></param>
        /// <returns></returns>
        public async Task<ApiResult> robot_config_unlock_req(RequestDTO requestDTO)
        {
            RequestDTO request = new RequestDTO();
            request.vehiclePort = vehiclePort;
            request.vehicleIP = requestDTO.vehicleIP;
            request.number = 4006;
            request.askJson = "";
            try
            {
                SeerTcpClient client = new SeerTcpClient(requestDTO.vehicleIP, request.vehiclePort);
                if (client.Connected)
                {
                    var str = client.SendseerMessage(request); 
                    return await Task.Run(async () => ApiResult.Success("ok", JsonConvert.DeserializeObject<ResponseVO>(str)));
                }
                else 
                    return await Task.Run(async () => ApiResult.Error("机器人网络连接断开，请检查网络")); 
            }
            catch (SocketException)
            {
                return await Task.Run(async () => ApiResult.Error("SocketException"));
            }
            catch (IOException)
            {
                return await Task.Run(async () => ApiResult.Error("IOException"));
            }
        }
        /// <summary>
        /// 清除货物形状 4356 
        /// </summary>
        /// <param name="requestDTO"></param>
        /// <returns></returns>
        public async Task<ApiResult> robot_config_clear_goodsshape_req(RequestDTO requestDTO)
        {
            RequestDTO request = new RequestDTO();
            request.vehiclePort = vehiclePort;
            request.vehicleIP = requestDTO.vehicleIP;
            request.number = 4356;
            request.askJson = "";
            try
            {
                SeerTcpClient client = new SeerTcpClient(requestDTO.vehicleIP, request.vehiclePort);
                if (client.Connected)
                {
                    var str = client.SendseerMessage(request);
                    return await Task.Run(async () => ApiResult.Success("ok", JsonConvert.DeserializeObject<ResponseVO>(str)));
                }
                else
                    return await Task.Run(async () => ApiResult.Error("机器人网络连接断开，请检查网络"));
            }
            catch (SocketException)
            {
                return await Task.Run(async () => ApiResult.Error("SocketException"));
            }
            catch (IOException)
            {
                return await Task.Run(async () => ApiResult.Error("IOException"));
            }
        }
        /// <summary>
        /// 设置货架描述文件 4357 
        /// </summary>
        /// <param name="requestDTO"></param>
        /// <returns></returns>
        public async Task<ApiResult> robot_config_set_shelfshape_req(RequestDTO<robot_config_set_shelfshape_DTO> requestDTO)
        {
            RequestDTO request = new RequestDTO();
            request.vehiclePort = vehiclePort;
            request.vehicleIP = requestDTO.vehicleIP;
            request.number = 4357;
            request.askJson = JsonConvert.SerializeObject(requestDTO.askJson);
            try
            {
                SeerTcpClient client = new SeerTcpClient(requestDTO.vehicleIP, request.vehiclePort);
                if (client.Connected)
                {
                    var str = client.SendseerMessage(request);
                    return await Task.Run(async () => ApiResult.Success("ok", JsonConvert.DeserializeObject<ResponseVO>(str)));
                }
                else
                    return await Task.Run(async () => ApiResult.Error("机器人网络连接断开，请检查网络"));
            }
            catch (SocketException)
            {
                return await Task.Run(async () => ApiResult.Error("SocketException"));
            }
            catch (IOException)
            {
                return await Task.Run(async () => ApiResult.Error("IOException"));
            }
        }
        /// <summary>
        /// 移除动态障碍物 4352
        /// </summary>
        /// <param name="requestDTO"></param>
        /// <returns></returns>
        public async Task<ApiResult> robot_config_removeobstacle_req(RequestDTO<robot_config_removeobstacle_DTO> requestDTO)
        {
            RequestDTO request = new RequestDTO();
            request.vehiclePort = vehiclePort;
            request.vehicleIP = requestDTO.vehicleIP;
            request.number = 4352;
            request.askJson = JsonConvert.SerializeObject(requestDTO.askJson);
            try
            {
                SeerTcpClient client = new SeerTcpClient(requestDTO.vehicleIP, request.vehiclePort);
                if (client.Connected)
                {
                    var str = client.SendseerMessage(request);
                    return await Task.Run(async () => ApiResult.Success("ok", JsonConvert.DeserializeObject<ResponseVO>(str)));
                }
                else
                    return await Task.Run(async () => ApiResult.Error("机器人网络连接断开，请检查网络"));
            }
            catch (SocketException)
            {
                return await Task.Run(async () => ApiResult.Error("SocketException"));
            }
            catch (IOException)
            {
                return await Task.Run(async () => ApiResult.Error("IOException"));
            }
        }
        /// <summary>
        /// 删除机器人上的地图 4012 
        /// </summary>
        /// <param name="requestDTO"></param>
        /// <returns></returns>
        public async Task<ApiResult> robot_config_removemap_req(RequestDTO<robot_config_removemap_DTO> requestDTO)
        {
            RequestDTO request = new RequestDTO();
            request.vehiclePort = vehiclePort;
            request.vehicleIP = requestDTO.vehicleIP;
            request.number = 4012;
            request.askJson = JsonConvert.SerializeObject(requestDTO.askJson);
            try
            {
                SeerTcpClient client = new SeerTcpClient(requestDTO.vehicleIP, request.vehiclePort);
                if (client.Connected)
                {
                    var str = client.SendseerMessage(request);
                    return await Task.Run(async () => ApiResult.Success("ok", JsonConvert.DeserializeObject<ResponseVO>(str)));
                }
                else
                    return await Task.Run(async () => ApiResult.Error("机器人网络连接断开，请检查网络"));
            }
            catch (SocketException)
            {
                return await Task.Run(async () => ApiResult.Error("SocketException"));
            }
            catch (IOException)
            {
                return await Task.Run(async () => ApiResult.Error("IOException"));
            }
        }
        /// <summary>
        /// 临时修改机器人参数 4100  
        /// </summary>
        /// <param name="requestDTO"></param>
        /// <returns></returns>
        public async Task<ApiResult> robot_config_setparams_req(RequestDTO<robot_config_setparams_DTO> requestDTO)
        {
            RequestDTO request = new RequestDTO();
            request.vehiclePort = vehiclePort;
            request.vehicleIP = requestDTO.vehicleIP;
            request.number = 4100;
            request.askJson = JsonConvert.SerializeObject(requestDTO.askJson);
            try
            {
                SeerTcpClient client = new SeerTcpClient(requestDTO.vehicleIP, request.vehiclePort);
                if (client.Connected)
                {
                    var str = client.SendseerMessage(request);
                    return await Task.Run(async () => ApiResult.Success("ok", JsonConvert.DeserializeObject<ResponseVO>(str)));
                }
                else
                    return await Task.Run(async () => ApiResult.Error("机器人网络连接断开，请检查网络"));
            }
            catch (SocketException)
            {
                return await Task.Run(async () => ApiResult.Error("SocketException"));
            }
            catch (IOException)
            {
                return await Task.Run(async () => ApiResult.Error("IOException"));
            }
        }
        /// <summary>
        /// 永久修改机器人参数 4101  
        /// </summary>
        /// <param name="requestDTO"></param>
        /// <returns></returns>
        public async Task<ApiResult> robot_config_saveparams_req(RequestDTO<robot_config_saveparams_DTO> requestDTO)
        {
            RequestDTO request = new RequestDTO();
            request.vehiclePort = vehiclePort;
            request.vehicleIP = requestDTO.vehicleIP;
            request.number = 4101;
            request.askJson = JsonConvert.SerializeObject(requestDTO.askJson);
            try
            {
                SeerTcpClient client = new SeerTcpClient(requestDTO.vehicleIP, request.vehiclePort);
                if (client.Connected)
                {
                    var str = client.SendseerMessage(request);
                    return await Task.Run(async () => ApiResult.Success("ok", JsonConvert.DeserializeObject<ResponseVO>(str)));
                }
                else
                    return await Task.Run(async () => ApiResult.Error("机器人网络连接断开，请检查网络"));
            }
            catch (SocketException)
            {
                return await Task.Run(async () => ApiResult.Error("SocketException"));
            }
            catch (IOException)
            {
                return await Task.Run(async () => ApiResult.Error("IOException"));
            }
        }
        /// <summary>
        /// 恢复机器人参数为默认值 4102  
        /// </summary>
        /// <param name="requestDTO"></param>
        /// <returns></returns>
        public async Task<ApiResult> robot_config_reloadparams_req(RequestDTO<robot_config_reloadparams_DTO> requestDTO)
        {
            RequestDTO request = new RequestDTO();
            request.vehiclePort = vehiclePort;
            request.vehicleIP = requestDTO.vehicleIP;
            request.number = 4102;
            request.askJson = JsonConvert.SerializeObject(requestDTO.askJson);
            try
            {
                SeerTcpClient client = new SeerTcpClient(requestDTO.vehicleIP, request.vehiclePort);
                if (client.Connected)
                {
                    var str = client.SendseerMessage(request);
                    return await Task.Run(async () => ApiResult.Success("ok", JsonConvert.DeserializeObject<ResponseVO>(str)));
                }
                else
                    return await Task.Run(async () => ApiResult.Error("机器人网络连接断开，请检查网络"));
            }
            catch (SocketException)
            {
                return await Task.Run(async () => ApiResult.Error("SocketException"));
            }
            catch (IOException)
            {
                return await Task.Run(async () => ApiResult.Error("IOException"));
            }
        }
        /// <summary>
        /// 配置机器人推送端口 4091   
        /// </summary>
        /// <param name="requestDTO"></param>
        /// <returns></returns>
        public async Task<ApiResult> robot_config_push_req(RequestDTO<robot_config_push_DTO> requestDTO)
        {
            RequestDTO request = new RequestDTO();
            request.vehiclePort = vehiclePort;
            request.vehicleIP = requestDTO.vehicleIP;
            request.number = 4091;
            request.askJson = JsonConvert.SerializeObject(requestDTO.askJson);
            try
            {
                SeerTcpClient client = new SeerTcpClient(requestDTO.vehicleIP, request.vehiclePort);
                if (client.Connected)
                {
                    var str = client.SendseerMessage(request);
                    return await Task.Run(async () => ApiResult.Success("ok", JsonConvert.DeserializeObject<ResponseVO>(str)));
                }
                else
                    return await Task.Run(async () => ApiResult.Error("机器人网络连接断开，请检查网络"));
            }
            catch (SocketException)
            {
                return await Task.Run(async () => ApiResult.Error("SocketException"));
            }
            catch (IOException)
            {
                return await Task.Run(async () => ApiResult.Error("IOException"));
            }
        }
        /// <summary>
        /// 从机器人下载地图 4011    
        /// </summary>
        /// <param name="requestDTO"></param>
        /// <returns></returns>
        public async Task<ApiResult> robot_config_downloadmap_req(RequestDTO<robot_config_downloadmap_DTO> requestDTO)
        {
            RequestDTO request = new RequestDTO();
            request.vehiclePort = vehiclePort;
            request.vehicleIP = requestDTO.vehicleIP;
            request.number = 4011;
            request.askJson = JsonConvert.SerializeObject(requestDTO.askJson);
            try
            {
                SeerTcpClient client = new SeerTcpClient(requestDTO.vehicleIP, request.vehiclePort);
                if (client.Connected)
                {
                    var str = client.SendseerMessage(request);
                    return await Task.Run(async () => ApiResult.Success("ok", JsonConvert.DeserializeObject<robot_config_downloadmap_VO>(str)));
                }
                else
                    return await Task.Run(async () => ApiResult.Error("机器人网络连接断开，请检查网络"));
            }
            catch (SocketException)
            {
                return await Task.Run(async () => ApiResult.Error("SocketException"));
            }
            catch (IOException)
            {
                return await Task.Run(async () => ApiResult.Error("IOException"));
            }
        }
        /// <summary>
        /// 设置第三方 Warning 4802     
        /// </summary>
        /// <param name="requestDTO"></param>
        /// <returns></returns>
        public async Task<ApiResult> robot_config_setwarning_req(RequestDTO<robot_config_setwarning_DTO> requestDTO)
        {
            RequestDTO request = new RequestDTO();
            request.vehiclePort = vehiclePort;
            request.vehicleIP = requestDTO.vehicleIP;
            request.number = 4802;
            request.askJson = JsonConvert.SerializeObject(requestDTO.askJson);
            try
            {
                SeerTcpClient client = new SeerTcpClient(requestDTO.vehicleIP, request.vehiclePort);
                if (client.Connected)
                {
                    var str = client.SendseerMessage(request);
                    return await Task.Run(async () => ApiResult.Success("ok", JsonConvert.DeserializeObject<ResponseVO>(str)));
                }
                else
                    return await Task.Run(async () => ApiResult.Error("机器人网络连接断开，请检查网络"));
            }
            catch (SocketException)
            {
                return await Task.Run(async () => ApiResult.Error("SocketException"));
            }
            catch (IOException)
            {
                return await Task.Run(async () => ApiResult.Error("IOException"));
            }
        }
        /// <summary>
        /// 清除第三方 Warning 4803   
        /// </summary>
        /// <param name="requestDTO"></param>
        /// <returns></returns>
        public async Task<ApiResult> robot_config_clearwarning_req(RequestDTO requestDTO)
        {
            RequestDTO request = new RequestDTO();
            request.vehiclePort = vehiclePort;
            request.vehicleIP = requestDTO.vehicleIP;
            request.number = 4803;
            request.askJson = "";
            try
            {
                SeerTcpClient client = new SeerTcpClient(requestDTO.vehicleIP, request.vehiclePort);
                if (client.Connected)
                {
                    var str = client.SendseerMessage(request);
                    return await Task.Run(async () => ApiResult.Success("ok", JsonConvert.DeserializeObject<ResponseVO>(str)));
                }
                else
                    return await Task.Run(async () => ApiResult.Error("机器人网络连接断开，请检查网络"));
            }
            catch (SocketException)
            {
                return await Task.Run(async () => ApiResult.Error("SocketException"));
            }
            catch (IOException)
            {
                return await Task.Run(async () => ApiResult.Error("IOException"));
            }
        }
        /// <summary>
        /// 设置第三方 Error 4800      
        /// </summary>
        /// <param name="requestDTO"></param>
        /// <returns></returns>
        public async Task<ApiResult> robot_config_seterror_req(RequestDTO<robot_config_seterror_DTO> requestDTO)
        {
            RequestDTO request = new RequestDTO();
            request.vehiclePort = vehiclePort;
            request.vehicleIP = requestDTO.vehicleIP;
            request.number = 4800;
            request.askJson = JsonConvert.SerializeObject(requestDTO.askJson);
            try
            {
                SeerTcpClient client = new SeerTcpClient(requestDTO.vehicleIP, request.vehiclePort);
                if (client.Connected)
                {
                    var str = client.SendseerMessage(request);
                    return await Task.Run(async () => ApiResult.Success("ok", JsonConvert.DeserializeObject<ResponseVO>(str)));
                }
                else
                    return await Task.Run(async () => ApiResult.Error("机器人网络连接断开，请检查网络"));
            }
            catch (SocketException)
            {
                return await Task.Run(async () => ApiResult.Error("SocketException"));
            }
            catch (IOException)
            {
                return await Task.Run(async () => ApiResult.Error("IOException"));
            }
        }
        /// <summary>
        /// 清除机器人当前所有报错 4009    
        /// </summary>
        /// <param name="requestDTO"></param>
        /// <returns></returns>
        public async Task<ApiResult> robot_config_clearallerrors_req(RequestDTO requestDTO)
        {
            RequestDTO request = new RequestDTO();
            request.vehiclePort = vehiclePort;
            request.vehicleIP = requestDTO.vehicleIP;
            request.number = 4009;
            request.askJson = "";
            try
            {
                SeerTcpClient client = new SeerTcpClient(requestDTO.vehicleIP, request.vehiclePort);
                if (client.Connected)
                {
                    var str = client.SendseerMessage(request);
                    return await Task.Run(async () => ApiResult.Success("ok", JsonConvert.DeserializeObject<ResponseVO>(str)));
                }
                else
                    return await Task.Run(async () => ApiResult.Error("机器人网络连接断开，请检查网络"));
            }
            catch (SocketException)
            {
                return await Task.Run(async () => ApiResult.Error("SocketException"));
            }
            catch (IOException)
            {
                return await Task.Run(async () => ApiResult.Error("IOException"));
            }
        }
        /// <summary>
        /// 运行信息复位 4450     
        /// </summary>
        /// <param name="requestDTO"></param>
        /// <returns></returns>
        public async Task<ApiResult> robot_config_clear_odo_req(RequestDTO requestDTO)
        {
            RequestDTO request = new RequestDTO();
            request.vehiclePort = vehiclePort;
            request.vehicleIP = requestDTO.vehicleIP;
            request.number = 4450;
            request.askJson = "";
            try
            {
                SeerTcpClient client = new SeerTcpClient(requestDTO.vehicleIP, request.vehiclePort);
                if (client.Connected)
                {
                    var str = client.SendseerMessage(request);
                    return await Task.Run(async () => ApiResult.Success("ok", JsonConvert.DeserializeObject<ResponseVO>(str)));
                }
                else
                    return await Task.Run(async () => ApiResult.Error("机器人网络连接断开，请检查网络"));
            }
            catch (SocketException)
            {
                return await Task.Run(async () => ApiResult.Error("SocketException"));
            }
            catch (IOException)
            {
                return await Task.Run(async () => ApiResult.Error("IOException"));
            }
        }
        /// <summary>
        /// 清除货架描述文件 4356      
        /// </summary>
        /// <param name="requestDTO"></param>
        /// <returns></returns>
        public async Task<ApiResult> robot_config_clear_shelfshape_req(RequestDTO requestDTO)
        {
            RequestDTO request = new RequestDTO();
            request.vehiclePort = vehiclePort;
            request.vehicleIP = requestDTO.vehicleIP;
            request.number = 4356;
            request.askJson = "";
            try
            {
                SeerTcpClient client = new SeerTcpClient(requestDTO.vehicleIP, request.vehiclePort);
                if (client.Connected)
                {
                    var str = client.SendseerMessage(request);
                    return await Task.Run(async () => ApiResult.Success("ok", JsonConvert.DeserializeObject<ResponseVO>(str)));
                }
                else
                    return await Task.Run(async () => ApiResult.Error("机器人网络连接断开，请检查网络"));
            }
            catch (SocketException)
            {
                return await Task.Run(async () => ApiResult.Error("SocketException"));
            }
            catch (IOException)
            {
                return await Task.Run(async () => ApiResult.Error("IOException"));
            }
        }
        /// <summary>
        /// 清除第三方 Error 4801       
        /// </summary>
        /// <param name="requestDTO"></param>
        /// <returns></returns>
        public async Task<ApiResult> robot_config_clearerror_req(RequestDTO requestDTO)
        {
            RequestDTO request = new RequestDTO();
            request.vehiclePort = vehiclePort;
            request.vehicleIP = requestDTO.vehicleIP;
            request.number = 4801;
            request.askJson = "";
            try
            {
                SeerTcpClient client = new SeerTcpClient(requestDTO.vehicleIP, request.vehiclePort);
                if (client.Connected)
                {
                    var str = client.SendseerMessage(request);
                    return await Task.Run(async () => ApiResult.Success("ok", JsonConvert.DeserializeObject<ResponseVO>(str)));
                }
                else
                    return await Task.Run(async () => ApiResult.Error("机器人网络连接断开，请检查网络"));
            }
            catch (SocketException)
            {
                return await Task.Run(async () => ApiResult.Error("SocketException"));
            }
            catch (IOException)
            {
                return await Task.Run(async () => ApiResult.Error("IOException"));
            }
        }
        /// <summary>
        /// 插入动态障碍物(机器人坐标系) 4350       
        /// </summary>
        /// <param name="requestDTO"></param>
        /// <returns></returns>
        public async Task<ApiResult> robot_config_addobstacle_req(RequestDTO<robot_config_addobstacle_DTO> requestDTO)
        {
            RequestDTO request = new RequestDTO();
            request.vehiclePort = vehiclePort;
            request.vehicleIP = requestDTO.vehicleIP;
            request.number = 4350;
            request.askJson = JsonConvert.SerializeObject(requestDTO.askJson);
            try
            {
                SeerTcpClient client = new SeerTcpClient(requestDTO.vehicleIP, request.vehiclePort);
                if (client.Connected)
                {
                    var str = client.SendseerMessage(request);
                    return await Task.Run(async () => ApiResult.Success("ok", JsonConvert.DeserializeObject<ResponseVO>(str)));
                }
                else
                    return await Task.Run(async () => ApiResult.Error("机器人网络连接断开，请检查网络"));
            }
            catch (SocketException)
            {
                return await Task.Run(async () => ApiResult.Error("SocketException"));
            }
            catch (IOException)
            {
                return await Task.Run(async () => ApiResult.Error("IOException"));
            }
        }
        /// <summary>
        /// 插入动态障碍物(世界坐标系) 4351        
        /// </summary>
        /// <param name="requestDTO"></param>
        /// <returns></returns>
        public async Task<ApiResult> robot_config_addgobstacle_req(RequestDTO<robot_config_addgobstacle_DTO> requestDTO)
        {
            RequestDTO request = new RequestDTO();
            request.vehiclePort = vehiclePort;
            request.vehicleIP = requestDTO.vehicleIP;
            request.number = 4351;
            request.askJson = JsonConvert.SerializeObject(requestDTO.askJson);
            try
            {
                SeerTcpClient client = new SeerTcpClient(requestDTO.vehicleIP, request.vehiclePort);
                if (client.Connected)
                {
                    var str = client.SendseerMessage(request);
                    return await Task.Run(async () => ApiResult.Success("ok", JsonConvert.DeserializeObject<ResponseVO>(str)));
                }
                else
                    return await Task.Run(async () => ApiResult.Error("机器人网络连接断开，请检查网络"));
            }
            catch (SocketException)
            {
                return await Task.Run(async () => ApiResult.Error("SocketException"));
            }
            catch (IOException)
            {
                return await Task.Run(async () => ApiResult.Error("IOException"));
            }
        }
         
    }
}
